//
//  MBaseViewController.m
//  zwyb
//
//  Created by 阔 李 on 16/11/3.
//  Copyright © 2016年 yxnzb. All rights reserved.
//

#import "MBaseViewController.h"

// 判断是否为iOS7
#define iOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)

@interface MBaseViewController ()

@end

@implementation MBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //  不让顶部nav占位 不透明处理
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
    
    // iOS7顶部屏幕适配
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]){
        
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    
#endif
    
    self.view.backgroundColor=[UIColor whiteColor];
    
    [self initNavLeftBtn];
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}

#pragma mark 初始化nav left
-(void)initNavLeftBtn{
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, screenScale(20), screenScale(20));
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"back_icon"] forState:UIControlStateNormal];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"back_icon"] forState:UIControlStateSelected];
    [leftBtn addTarget:self action:@selector(leftNavItemClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarBtn = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftBarBtn;
}

-(void)leftNavItemClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 隐藏navleft
- (void)leftNavHide{
    
    self.navigationItem.leftBarButtonItem.customView.hidden = YES;
}

#pragma mark 隐藏navright
- (void)rightNavHide{
    
    self.navigationItem.rightBarButtonItem.customView.hidden=YES;
}
#pragma mark 复写title
-(void)setTitle:(NSString *)title{
    
    [super setTitle:title];
    
    UILabel *titlelabel = [[UILabel alloc]initWithFrame:CGRectZero];
    titlelabel.backgroundColor = [UIColor clearColor];
    titlelabel.text = title;
    titlelabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:(18)];
    titlelabel.textColor = [ZJCModel colorWithString:@"000000"];
    
    [titlelabel sizeToFit];
    self.navigationItem.titleView = titlelabel;
    
}

@end
